﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestLoanCalculator.aspx.cs" Inherits="CRMWeb.Pages.Test.TestLoanCalculator" %>

<!DOCTYPE html>

<head id="Head1" runat="server">
    <title>Laon Calculator</title>
    <script src="../../Scripts/jquery-1.7.2.min.js"></script>
    <script src="../../Scripts/jacs.js"></script>
    <link href="../../EasyUI/Themes/icon.css" rel="stylesheet" />
    <link href="../../EasyUI/Themes/default/easyui.css" rel="stylesheet" />
    <script src="../../EasyUI/jquery.easyui.min.js"></script>
    <script type="text/javascript" >
        function calculateLoan(IsUpdate) {
            $("#loading").html("Loading...");
            var arr = "{'app_id':'12345678',"+
                "'frequency':'"+$("#<%=ddlFrequency.ClientID%>").val()+"',"+
                "'principal':'"+$("#<%=txtPrincipal.ClientID%>").val()+"',"+
                "'LoanDuration':'"+$("#<%=txtLoanDuration.ClientID%>").val()+"',"+
                 "'InterestRate':'"+$("#<%=txtInterestRate.ClientID%>").val()+"',"+
                 "'FirstRepaymentDate':'"+ $("#<%=txtFirstRepayment.ClientID%>").val()+"',"+
                 "'LoanDate': '"+$("#<%=txtLoanDate.ClientID%>").val()+"',"+
                 "'OtherCharges':'"+$("#<%=txtOtherCharges.ClientID%>").val()+"'}";
                $.ajax({
                    url: "/WebServices/AM/MaccContractWS.ashx",
                    contentType: "application/json; charset=utf-8",
                    type: "POST",
                    datatype: "JSON",
                    data:arr,
                    success: function (data) { 
                        writeHTML(data);
                        $("#loading").html("");
                    },
                    error: function (err) { message(err.responseText); 
                        $("#loading").html("");}
                })
            return false;
        }
        function message(msg)
        {
            $.messager.show({
                title:'Interest Calculator',
                msg:msg,
                showType:'show',
                timeout:0,
                style:{
                    right:'',
                    top:document.body.scrollTop+document.documentElement.scrollTop,
                    bottom:'',
                }
            });
        }
        function writeHTML(data) {
            if(data.Result)
            {
                if(data.Result.length>0)
                {
                    $("#totalinterest").html(data.Result[0].Totalinterest);
                    $("#re_payment").html(data.Result[0].Repayment);
                    $("#anualcostrate").html(data.Result[0].Annualcostrate);
                    var cdata = [[{ field: "Payhash", title: "",width:200 }, 
                         { field: "Date", title: "Due Date",width:300 }, 
                         { field: "Amount", title: "Amount Due",width:300 } 
                    ]];
                    var output_payment=data.Payment;
                    $("#Paymentduedate").datagrid({
                        columns: cdata,
                        data: output_payment
                    });
                }
            }
}
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table cellpadding="5"  cellspacing="0" >
            <tr>
                <td colspan="2" style="text-align:center">Loan Calculator</td>
            </tr>
            <tr>
                <td>Select Frequency</td>
                <td><asp:DropDownList ID="ddlFrequency" runat="server" >
                    <asp:ListItem Text="Weekly" Value="0"></asp:ListItem>  
                    <asp:ListItem Text="Fortnighty" Value="1"></asp:ListItem>  
                    <asp:ListItem Text="Monthly" Value="2"></asp:ListItem>  
                </asp:DropDownList></td>
            </tr>
            <tr>
                <td>Principal</td>
                <td>
                    <asp:TextBox ID="txtPrincipal" runat="server" ></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>Loan Duration (in week)</td>
                <td>
                    <asp:TextBox ID="txtLoanDuration" runat="server" ></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>Interest Rate</td>
                <td><asp:TextBox ID="txtInterestRate" runat="server" ></asp:TextBox>
                </td>

            </tr><tr>
                <td>Loan Date</td>
                <td><asp:TextBox ID="txtLoanDate" runat="server" ></asp:TextBox>&nbsp;
                    <input name="btnLoanDate" value="+" id="btnLoanDate" type="button"  onclick="JACS.show(document.getElementById('<%=txtLoanDate.ClientID %> '),event);" /> 
                </td>
            </tr>
            <tr>
                <td>First Repayment Date</td>
                <td><asp:TextBox ID="txtFirstRepayment" runat="server" ></asp:TextBox>
                   <input name="btnLoanDate" value="+" id="btnFirstRepayment" type="button"  onclick="JACS.show(document.getElementById('<%=txtFirstRepayment.ClientID %>'),event);" /> 
                </td>
            </tr>
            <tr>
                <td>Other Charges </td>
                <td><asp:TextBox ID="txtOtherCharges" runat="server" Text="0"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                   <div style="float:left; width:120px"><div style="float:left"><asp:Button ID="btnCalculate" runat="server" OnClientClick="return calculateLoan('false');" ValidationGroup="cal"  Text="Calculate" /></div><div style="float:left"></div></div>
                    <div style="float:left" id="loading"></div>
                </td>
            </tr>
        </table>  
        <table cellpadding="5" cellspacing="0" border="1" style="border-collapse:collapse" >
            <tr><td>Repayment</td><td id="re_payment">&nbsp;</td></tr>
            <tr><td>Anual Cost Rate</td><td id="anualcostrate">&nbsp;</td></tr>
            <tr><td>Total Interest</td><td id="totalinterest">&nbsp;</td></tr>
        </table>
        <table id="Paymentduedate" cellpadding="0" cellspacing="0" width="100%" border="1" style="border-collapse:collapse" >
                                </table>
    </div>
    </form>
</body>
</html>
